#include <stdio.h>

int main(void)
{
    int on_switch = 0, sright = 0, sfront =0, sleft=0, slight=0;
    int rightmotor=0, leftmotor=0, targetlight=0;

    printf("\n on_switch (1/0):");
    scanf("%d",&on_switch);

    test: while(on_switch == 1 )
            {
                sright = 0, sfront =0, sleft=0, slight=0;
                rightmotor=0, leftmotor=0, targetlight=0;
                printf("\n\n Light sensor: ");
                scanf("%d", &slight);
                if (slight > 7)
                    {goto target;}
                else
                    {printf("\n Right sensor: ");
                    scanf("%d", &sright);
                    }
                if (sright == 0)
                    {rightmotor = 0;         //no right wall turn right
                    leftmotor = 1;
                    printf("\n Turning Right.");
                    goto test;
                    }
                else
                    {printf("\n Front sensor: ");
                    scanf("%d", &sfront);}
                if (sfront == 0)
                    {
                    rightmotor = 1;         //There is a right wall and no front wall, go straight
                    leftmotor = 1;
                    printf("\n Going Straight.");
                    goto test;
                    }
                else
                    {printf("\n Left sensor: ");
                    scanf("%d", &sleft);}
                if (sleft == 0)
                    {
                    rightmotor = 1;         //There is a right wall and a front wall, no left wall go left
                    leftmotor = 0;
                    printf("\n Turning Left.");
                    goto test;
                    }
                else
                    {
                    rightmotor = 2;         //There is a right wall, a front wall, and left wall, turn twice to face opposit direction
                    leftmotor = 0;
                    printf("\n Turning Around.");
                    goto test;
                    }

            }

    target: {
               rightmotor = 0;
               leftmotor = 0;
               targetlight = 1;
               printf("\n\n Target Found!\n");
            }
   return 0;
}

